package com.xiaochong.tir.api.controller;

import com.xiaochong.tir.api.service.CoinSummerizeService;
import com.xiaochong.tir.api.service.CurrencyDiagnosisService;
import com.xiaochong.tir.api.service.TokenIndexRankService;
import com.xiaochong.tir.api.util.ApiVersion;
import com.xiaochong.tir.common.data.hbasepo.KLineCmcData;
import com.xiaochong.tir.common.data.hbasepo.PopularityIndicator;
import com.xiaochong.tir.common.data.mapper.CoinSummarizeMapper;
import com.xiaochong.tir.common.data.po.CoinSummarize;
import com.xiaochong.tir.common.data.vo.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * Created by org on 2018/5/2.
 */
@Api(value="货币诊断")
@RestController
@RequestMapping(ApiVersion.API_V1_PREFIX+"/diagnose")
public class CurrencyDiagnosisController {

    @Autowired
    private CurrencyDiagnosisService currencyDiagnosisService;

    @Autowired
    private CoinSummerizeService coinSummerizeService;

    @ApiOperation(value = "量化评估-市场热度", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cmc_id", value = "货币id", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/marketHeatList")
    public ApiResultVo<ApiMarketHeatVo> getMarketHeatList(@RequestParam(value = "cmc_id") String cmc_id){
        return currencyDiagnosisService.getMarketHeatList(cmc_id);
    }
    @ApiOperation(value = "量化评估-量能变化", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cmc_id", value = "货币id", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/energyVolumeChange")
    public ApiResultVo<ApiEnergyVolumeChangeVo> getEnergyVolumeChange(@RequestParam(value = "cmc_id") String cmc_id){
        //long start = System.currentTimeMillis();
        ApiResultVo<ApiEnergyVolumeChangeVo> o = currencyDiagnosisService.getEnergyVolumeChange(cmc_id);
        //long end = System.currentTimeMillis();
        //System.out.println(end-start);
        return o;
    }
    @ApiOperation(value = "量化评估-货币流动性", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cmc_id", value = "货币id", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/currencyExchangeRate")
    public ApiResultVo<ApiCurrencyExchangeRatetVo> getCurrencyExchangeRate(@RequestParam(value = "cmc_id") String cmc_id){
        return currencyDiagnosisService.getCurrencyExchangeRate(cmc_id);
    }
    @ApiOperation(value = "量化评估-人气意愿指标", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cmc_id", value = "货币id", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/popularityARIndex")
    public ApiResultVo<ApiPopularityARIndexVo> getPopularityARIndex(@RequestParam(value = "cmc_id") String cmc_id){
        return currencyDiagnosisService.getPopularityARIndexOfHours(cmc_id);
    }
    @ApiOperation(value = "量化评估-诊断得分", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cmc_id", value = "货币id", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/currencyDiagnosisScore")
    public ApiResultVo<ApiCurrencyDiagnosisScoreVo> getCurrencyDiagnosisScore(@RequestParam(value = "cmc_id") String cmc_id){
        return currencyDiagnosisService.getCurrencyDiagnosisScore(cmc_id);
    }

    @ApiOperation(value = "获取启用的货币信息", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @GetMapping("/allEnableCurrencyInfo")
    public ApiResultVo<List<ApiAllEnableCurrencyInfoVo>> getAllEnableCurrencyInfoList(){
        return currencyDiagnosisService.getAllEnableCurrencyInfoList();
    }

    @ApiOperation(value = "获取CMC货日K数据", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @GetMapping("/getCmcKline")
    public ApiResultVo<List<ApiKLineCmcData>> getCmcKline(
                                            @RequestParam(value = "cmcId") String cmcId,
                                            @ApiParam(value = "按月份来分页，1 当前一个月的数据，2当前两个月的数据，依次推") @RequestParam(value = "page")  Integer page){
        return currencyDiagnosisService.getCmcKline(cmcId , page );
    }
    /**
     * 组装ar人气意愿指标到redis中
     * @return
     */
    /*@ApiOperation(value = "组装人气ar人气数据到redis", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @PostMapping("/makePopularityARIndexData")
    public ApiResultVo makePopularityARIndexData(@RequestBody List<PopularityIndicator> cmdIdList){
        return currencyDiagnosisService.makePopularityARIndexData(cmdIdList);
    }*/
    @ApiOperation(value = "货币项目概括", notes = "返回code：1000-成功；2000-无数据；5000-查询失败；")
    @GetMapping("/getProjectOverview")
    public ApiResultVo<ProjectOverviewVo> getProjectOverview(@RequestParam(value = "cmcId") String cmcId){
        return coinSummerizeService.getProjectOverviewByCmcId(cmcId);
    }
}
